package com.lam.common.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.domain.Result;
import com.lam.common.validate.ValidateUtil;
import com.lam.common.validate.model.ValidOperType;
import com.lam.framework.annotation.ParamInject;
import com.lam.framework.operLog.annotation.Log;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.framework.operLog.model.OperateLog;

@Log(title = "公共功能接口")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/func")
public class CommonFunctionController {
	
	/**
	 * 唯一字段判断
	 * @param code 配置编码
	 * @param operType 编辑类型
	 * @param param 参数
	 * @param operateLog 日志
	 * @return
	 */
	@Log(oper = "唯一字段判断", businessType = BusinessType.CHECK_UNIQUE)
	@PostMapping("/chkUq/{code}/{operType}")
	public Result checkUnique(@PathVariable("code") String code, @PathVariable("operType") String operTypeStr, 
			@RequestBody Map<String, Object> param, OperateLog operateLog) {
		
		ValidateUtil.validRequired(code, "code不能为空！");
		ValidateUtil.validRequired(operTypeStr, "operType不能为空！");
		ValidOperType operType = ValidOperType.valueFrom(operTypeStr);
		ValidateUtil.validRequired(operType, "不支持的operType！");
		
		return Result.ok().data(ValidateUtil.validUnique(param, operType, code));
	}
	

}
